/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.TimeUnit;

/**
 * <p>在一对象中，同步方法，能不能调用非调用方法。能，非同步方法不需锁
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ex10 {
    synchronized void work() {
        String tn = Thread.currentThread().getName();
        for (int i = 0; i < 3; i++) {
            System.out.printf("%s-%d%n", tn, i);
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    synchronized void show() {
        System.out.println("show()......");
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        var ex = new Ex10();
        new Thread(ex::work, "T1").start();
        new Thread(ex::show, "T2").start();
    }
}
